import { httpPost, httpGet } from '@/libs/http'
import { getToken } from '@/libs/util.js'

export default function (Vue, options) {
    // 获得联系人字典
    Vue.prototype.getCustomsList = function () {
        let tempArr = []
        let data = {
            custType: '',
            username: '',
            pageNum: 1,
            pageSize: 10000
        }
        let url = '/customs/customerManagement/query'
        httpPost(url, data).then(res => {
            if (res.isSuccess) {
                let list = res.data.list
                if (list.length > 0) {
                    tempArr.push(...list)
                }
            }
        })
        return tempArr
    }

    // 获得数据字典公共方法
    Vue.prototype.getDataListCommFn = function (options) {
        let cacheData = sessionStorage.getItem(options.sessionKey)
        if (cacheData) {
            return JSON.parse(cacheData)
        }

        let tempArr = []
        let data = {
            dataMainType: options.dataMainType,
            pageNum: 1,
            pageSize: 10000
        }
        let declareUrl = '/ui/commonbasicdata/basicData/getCustomsBasicDataVo'
        let manifestUrl = '/customs/manifestBasicData/list'
        let url = options.type === 1 ? declareUrl : manifestUrl // type: 1-报关单基础数据字典接口  2-舱单基础数据字典接口

        httpPost(url, data).then(res => {
            if (res.isSuccess) {
                let list = res.data.list
                sessionStorage.setItem(options.sessionKey, JSON.stringify(list))
                if (list.length > 0) {
                    tempArr.push(...list)
                }
            }
        })
        return tempArr
    }

    Vue.prototype.getAgentCodeList = function (options, cb) {
        let url = '/customs/agent/queryAgentByKeyWord?type=4' + '&keyWord=' + options.keyWord + '&Authorization=' + getToken()
        let tempArr = []
        httpGet(url).then(res => {
            if (res.isSuccess) {
                let list = res.data
                if (list.length > 0) {
                    tempArr.push(...list)
                }
                cb && cb(res.data)
            }
        })
        return tempArr
    }
}
